import * as user from '@/api/user.js'
import * as index from '@/api/index.js'
import MultipleSelect from '@/components/multiple-select/index.vue'
import {
	baseURL
} from '@/common/config.js'
export default {
components: {
	MultipleSelect
	},
	name: "contacts",
	data() {
		return {
			placeholder:'',
			welfare: false,
			welfare_arr: [],
			welfare_ids: [],
			welfare_name: '请选择',
			from:{
				license: '',
				name: '',
				nature: '请选择雇主性质',
				natureId: '',
				scale: '请选择雇主规模',
				scaleId: '',
				welfare: '请选择福利待遇',
				welfareId: '',
				region: '请选择所在地区',
				regionId: '',
				site:'',
				phone: '',
				introduction: '',
				address: '',
				latitude: '',
				longitude: ''
			},
			errorstate:'',//错误状态
			no_tis:'',//错误提示
			state:'',//审核状态
			introductionNo: '',
			isBusiness: false, //营业执照
			isName: false, //雇主全称
			isNature: false, //雇主性质
			isScale: false, //雇主规模
			isWelfare: false, // 福利待遇
			isRegion: false, //所在地区
			isSite: false, //地址
			isPhone: false, //电话
			isIntroduction: false, // 雇主简介
			natureList: [ //雇主性质列表
			],
			natureShow: false, //雇主性质选择框
			scaleList: [ //雇主规模列表
			],
			scaleShow: false, //雇主规模选择框
			welfareList: [ //福利待遇列表
			],
			welfareShow: false, // 福利待遇选择框
			regionList: [ //所在地区列表
			],
			regionShow: false, // 所在地区选择框
		};
	},
	onLoad() {
		this.getSelect()
		this.getfrom()
	},
	onShow() {

	},
	methods: {
		// 获取资料信息
		getfrom() {
			user.getMemberCompanyInfo().then(res=>{
				this.from.phone = res.data.phone
				this.introductionNo = res.data.txt_tis
				this.from.name = res.data.name || this.from.name, //名字
				this.from.license = res.data.license || this.from.license, // 营业执照
				this.from.scaleId = res.data.scale || this.from.scaleId, //雇主规模
				this.from.scale = res.data.scale_text || this.from.scale
				this.from.natureId = res.data.nature_id || this.from.natureId, //雇主性质
				this.from.nature = res.data.nature_text ||this.from.nature
				this.from.regionId = res.data.areas || this.from.regionId, //地区
				this.from.region = res.data.areas_text || this.from.region,
				this.from.welfare = res.data.welfare || this.from.welfare, //福利待遇
				this.from.address = res.data.address || this.from.address, //地址
				this.from.site = res.data.addresss || this.from.site, //详细地址
				this.from.longitude = res.data.longitude || this.from.longitude, //经度
				this.from.latitude = res.data.latitude || this.from.latitude, //纬度
				this.from.phone = res.data.tel || this.from.phone, //联系电话
				this.from.introduction = res.data.txt || this.from.introduction //雇主简介
				this.welfare_name = res.data.welfare_text.map(el => el.title).join(",") || this.welfare_name
				this.welfare_ids = res.data.welfare || this.welfare_ids
				this.no_tis = res.data.no_tis
				this.state = res.data.state
			})
		},
		ok_welfare(data) {
			this.welfare_name = data.map(el => el.title).join(",");
			this.from.welfare = data.map(el => el.id).join(",");
			
		},
		// 上传营业执照
		addImgebnt() {
			this.isBusiness = false
			uni.chooseImage({
				success: (chooseImageRes) => {
					const tempFilePaths = chooseImageRes.tempFilePaths;
					uni.uploadFile({
						url:baseURL+'zp_common_v1/upload', 
						filePath: tempFilePaths[0],
						name: 'file',
						header: {
							//#ifdef APP-PLUS
							'type': 1,
							//#endif
							'Content-type': 'application/json',
							'token': uni.getStorageSync('token')
						}, 
						success: (uploadFileRes) => {
							console.log(uploadFileRes);
							this.from.license = JSON.parse(uploadFileRes.data).data.fullurl
						}
					});
				}
			});
		},
		// 放大预览
		showBigImg(){
			let arr=[];
			arr.push(this.from.license)
			uni.previewImage({
			  current: 0,
			  urls: arr
			});
		},
		// 获取下拉列表数据
		getSelect() {
			// 获取雇主性质
			user.getNatureList().then(res=>{
				this.natureList = res.data
			})
			// 获取福利待遇
			user.getWelfareList().then(res=>{
				this.welfare_arr = res.data
			})
			// 获取需求区域
			user.getAreasList({pid:1}).then(res=>{
				this.regionList = res.data
			})
			// 获取雇主规模
			user.getScaleList().then(res=>{
				this.scaleList = res.data
			})
			index.nameGetConfig({name:'txt_tis'}).then(res=>{
				this.placeholder = res.data.txt_tis
			})
			// select().then(res=>{
			// 	this.natureList[0] = res.nature //雇主性质列表
			// 	this.scaleList[0] = res.scale //雇主规模列表
			// 	// this.welfareList[0] = res.welfare //福利待遇列表
			// 	this.regionList[0] = res.areas //所在地区列表
			// 	this.welfare_arr = res.welfare //福利待遇列表
			// })
		},
		get_address() {
			this.isSite = false
			uni.chooseLocation({
				success: (res)=> {
					this.from.address = res.name;
					this.from.latitude = res.latitude;
					this.from.longitude = res.longitude;
				}
			});
		},
		saveBnt() {
			if(!this.from.license) {
				this.$tools.toast('请上传营业执照');
				this.isBusiness = true
				return
			}
			if(!this.from.name) {
				this.$tools.toast('请输入雇主全称');
				this.isName = true
				return
			}
			if(this.from.nature == '请选择雇主性质') {
				this.$tools.toast('请选择雇主性质');
				this.isNature = true
				return
			}
			if(this.from.scale == '请选择雇主规模') {
				this.$tools.toast('请选择雇主规模');
				this.isScale = true
				return
			}
			if(this.from.welfare == '请选择福利待遇'||this.from.welfare == '') {
				this.$tools.toast('请选择福利待遇');
				this.isWelfare = true
				return
			}
			if(this.from.region == '请选择所在地区') {
				this.$tools.toast('请选择所在地区');
				this.isRegion = true
				return
			}
			if(!this.from.phone) {
				this.$tools.toast('请输入联系电话');
				this.isPhone = true
				return
			}
			// if(!this.from.address) {
			// 	this.$tools.toast('请选择地址');
			// 	this.isSite = true
			// 	return
			// }
			if(!this.from.introduction) {
				this.$tools.toast('请输入雇主简介');
				this.isIntroduction = true
				return
			}
			uni.showModal({
			    title: '提示',
			    content: '确定保存资料吗?',
			    success:(res)=> {
					if (res.confirm) {
						var data = {
							name: this.from.name, //名字
							logo: '', //logo
							license: this.from.license, // 营业执照
							scale: this.from.scaleId, //雇主规模
							nature_id: this.from.natureId, //雇主性质
							areas: this.from.regionId, //地区
							welfare: this.from.welfare, //福利待遇
							address: this.from.address, //地址
							addresss: this.from.site, //详细地址
							longitude: this.from.longitude, //经度
							latitude: this.from.latitude, //纬度
							tel: this.from.phone, //联系电话
							txt: this.from.introduction, //雇主简介
						}
						user.editMemberCompany(data).then(res=>{
							uni.navigateBack({
								data:1
							})
						})
					}
			    }
			})
		},
		//福利待遇
		welfareClick(){
			this.$refs.popup.open('bottom')
		},
		// 确定雇主性质按钮
		natureBnt(e) {
			this.from.nature = this.natureList[e.detail.value].title
			this.from.natureId = this.natureList[e.detail.value].id
			this.natureShow = false
			this.isNature = false
		},
		// 确定雇主规模按钮
		scaleBnt(e) {
			console.log(e)
			this.from.scale = this.scaleList[e.detail.value].title
			this.from.scaleId = this.scaleList[e.detail.value].id
			this.scaleShow = false
			this.isScale = false
		},
		// 确定福利待遇按钮
		welfareBnt(e) {
			this.from.welfare = e.value[0].title
			this.from.welfareId = e.value[0].id
			this.welfareShow = false
			this.isWelfare = false
		},
		// 确定所在地区按钮
		regionBnt(e) {
			this.from.region = this.regionList[e.detail.value].title
			this.from.regionId = this.regionList[e.detail.value].id
			this.regionShow = false
			this.isRegion = false
		},
	}
}